<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改图片</title>
<link href="${pageContext.request.contextPath }/css/common.css" type="text/css" rel="stylesheet"></link>
<link href="${pageContext.request.contextPath }/css/main.css" type="text/css" rel="stylesheet"></link>
	<script src="${pageContext.request.contextPath }/js/jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript">

window.onload = function () { 
	
    new uploadPreview({ UpBtn: "upload", DivShow: "imgdiv", ImgShow: "imgShow" });
}

function getFullPath(obj) {
	//得到图片的完整路径
	if (obj) {
		//ie
		if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
			obj.select();
			return document.selection.createRange().text;
			}
		//firefox
		else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
			if (obj.files) {
				return obj.files.item(0).getAsDataURL();
				}
			return obj.value;
			}
		return obj.value;
		}
	} 
	
$(document).ready(function(){
	$("#upload").change(function(){
		var strSrc = $("#upload").val();
		
		/* img = new Image();
		img.src = getFullPath(strSrc); */
		//验证上传文件格式是否正确
		var pos = strSrc.lastIndexOf(".");
		var lastname = strSrc.substring(pos, strSrc.length);
		if (lastname != ".jpg" && lastname != ".png") {
			alert("您上传的文件类型为" + lastname + "，图片必须为 jpg或png类型");
		}
	});
		$("#error").hide();
		$("#Picture_Name").blur(function(){

		if($(this).val() == ""){
			
			$("#error").show();
		}else{
			
			$("#error").hide();
		}
		});
		$("#sub").click(function(){
			
			if($("#upload").val() != ""){
				
				var strSrc = $("#upload").val();
				/* img = new Image();
				img.src = getFullPath(strSrc); */
				//验证上传文件格式是否正确
				var pos = strSrc.lastIndexOf(".");
				var lastname = strSrc.substring(pos, strSrc.length);
				
				if (lastname != ".jpg" && lastname != ".png") {
					alert("您上传的文件类型为" + lastname + "，图片必须为 jpg或png类型");
					return false;
				}  
			}else{
				alert("图片必须选。");
				return false;
			}
			if($("#Picture_Name").val() == ""){
				alert("图片名称必填。");
				return false;
			}
			
		});
	});
	
</script>
<script src="${pageContext.request.contextPath }/js/uploadPreview.js" type="text/javascript"></script>
<style type="text/css">
#preview{width:260px;height:190px;border:1px solid #000;overflow:hidden;}
#imghead {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);}
body { overflow-x: hidden; overflow-y: auto; } 
</style>
</head>
<body>
	<div style="width: 80%;margin-left: 10%;">
		<div class="result-wrap">
            <form action="${pageContext.request.contextPath }/managerA/updatePicture.action" method="post" enctype="multipart/form-data">
                <div class="config-items">
                    <div class="config-title">
                        <h1 style="font-size: 26px;font-family: Tahoma,Geneva,sans-serif;color: #666;">修改广告牌</h1>
                    </div>
                    <div class="result-content">
                        <table>
                        	<tr>
                        		<th width="60%">
                        		<table width="100%" class="insert-tab">
                            	<%-- <s:iterator value="#request.list" var="i"> --%>
                            	<tr>
                                <th width="15%"><i class="require-red">*</i>标题：
                                <td><input type="text" id="Picture_Name" size="85" name="Picture_Name" value="${name }" class="common-text">
                               <font id="error" color="red">图片标题不能为空。</font> </td>
                                
                            </tr>
                                <tr>
                                    <th><i class="require-red">*</i>是否发布：</th>
                                    <td>
                                    	<select style="width: 86%;height: 10%" id="IsPublish"  name="IsPublish" class="common-text">
                                    		<option value="false">否</option>
                                    		<option value="true">是</option>
                                    	</select>
                                    </td>
                                </tr>
                                <tr>
                                	<th></th>
                                	<th align="left"><div id="imgdiv" align="left"><img id="imgShow" src="${path }" width="100" height="100" /></div></th>
                                </tr>
                                 <tr>
                                    <th><i class="require-red">*</i>上传图片：</th>
                                    <td><input style="width: 64%" type="file" id="upload" size="85" name="upload" class="common-text">
                                    <span style="color: red;font-size: 12px;">请选择jpg或png格式的图片</span></td>
                                </tr>
                                <tr>
                                	<th><input type="hidden" id="id" name="id" value='${id }'></th>
                                </tr>
                            	<%-- </s:iterator> --%>
                                <tr>
                                    <th></th>
                                    <td>
                                        <input type="submit" id="sub" value="提交" class="btn btn-primary btn6 mr10">
                                        <input type="button" value="返回" onclick="history.go(-1)" class="btn btn6">
                                    </td>
                                </tr>
                            </table>
                        	</tr>
                        </table>
                    </div>
                </div>
            </form>
          </div>
	</div>
</body>
</html>